<?php   // $Id: devis_add_article.php 288 2008-09-20 09:35:54Z pcoustillas $ ?>
<?php   
/*Copyright (C) 2003-2004 Guy Hendrickx
Licensed under the terms of the GNU  General Public License:http://www.opensource.org/licenses/gpl-license.php
File Authors:Guy Hendrickx
Modification : Pierre Coustillas*/

require_once("include/verif.php");
require_once("include/config/common.php");

//$nom=isset($_POST['nom'])?$_POST['nom']:"";
$num_devis=isset($_POST['num_devis'])?$_POST['num_devis']:"";

$quanti=isset($_POST['quanti'])?$_POST['quanti']:"";
$article=isset($_POST['article'])?$_POST['article']:"";


//on recupere le prix htva		
$sql = "SELECT prix_htva,taux_tva FROM ${tblpref}article WHERE num = $article";
$result = mysql_query($sql) or die("Erreur SQL1 !<br/>$sql<br/>" . mysql_error());
//$prix_article = mysql_result($result, 'prix_htva');
//on recupere le taux de tva
//$sql3 = "SELECT  FROM " . $tblpref ."article WHERE num = $article";
//$result = mysql_query($sql3) or die('Erreur SQL2 !<br>'.$sql3.'<br>'.mysql_error());
//$taux_tva = mysql_result($result, 'taux_tva');

$data=mysql_fetch_array($result);
$prix_article = $data['prix_htva'];
$taux_tva = $data['taux_tva'];

$total_htva = $prix_article * $quanti ;
$mont_tva = $total_htva / 100 * $taux_tva ;
//inserer les données dans la table du contenu des devis.

//mysql_select_db($db) or die ("Could not select $db database");
$sql1 = "INSERT INTO ${tblpref}cont_dev(quanti, article_num, dev_num, tot_art_htva, to_tva_art)  
		VALUES ('$quanti', '$article', '$num_devis', '$total_htva', '$mont_tva')";
mysql_query($sql1) or die("Erreur ajout de l'article !<br/>$sql1<br/>".mysql_error());

header("Location: devis_edit.php?num_devis=$num_devis");

?>